package j_util.data_structures.queue;

import j_util.data_structures.nodus.Nodus;

/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
public class QueueD implements Queue {
    private Nodus first;
    private Nodus last;

    public QueueD() {
        first = new Nodus();
        last = first;
    }

    /**
     * This method allows to enqueue an element;
     *
     * @param o - Object;
     */
    public void enqueue(Object o) {
        Nodus nodus = new Nodus(o);
        last.setNext(nodus);
        last = nodus;
        /*Nodus nodus = new Nodus(o);
        if (first == null) {
            first = nodus;
            last = nodus;
        } else {
            last.setNext(nodus);
            last = nodus;
        }*/
    }


    /**
     * This method allows to dequeue an element;
     */
    public void dequeue() {
        first = first.getNext();
        /*first.setNext(first.getNext());
        if (first == null) {
            last = null;
        }*/
    }

    /**
     * This method allows to know if Queue object is empty.
     * Returns true if is empty, false if not;
     *
     * @return isEmpty - boolean;
     */
    public boolean isEmpty() {
        return first == last;
    }

    /**
     * This method allows getting the first object in the queue;
     *
     * @return object  - Object;
     */
    public Object getFront() {
        return first.getNext();
    }
}